<template>
    <div>
        <hd-tab :tabs="tabs"/>
        <el-form ref="form" :inline="false" :model="form" label-width="80px" size="normal">
            <el-card :body-style="{ padding: '20px' }" shadow="never">
                <div slot="header">
                    服务管理
                </div>
                <el-form-item label="名称">
                    <el-input v-model="form.name" placeholder="简介说明"></el-input>
                    <hd-error name="name"/>
                </el-form-item>
                <el-form-item label="图片">
                    <hd-image v-model="form.url"></hd-image>
                    <hd-error name="url"/>
                </el-form-item>
                <el-form-item label="介绍">
                    <el-input v-model="form.introduce" placeholder="服务介绍" type="textarea"></el-input>
                    <hd-error name="introduce"/>
                </el-form-item>
                <el-form-item label="内容">
                    <hd-wangedit v-if="loading" v-model="form.content"/>
                    <hd-error name="content"/>
                </el-form-item>
                <el-button type="primary" @click="onSubmit">提交</el-button>

            </el-card>
        </el-form>

    </div>
</template>

<script>
import tabs from './tabs'

export default {
    route: false,
    props: ['id'],
    data() {
        return {
            tabs,
            form: {},
            loading: false
        }
    },
    async created() {
        if (this.id) this.form = await this.axios.get(`admin/service/${this.id}`)
        this.loading = true
    },
    methods: {
        async onSubmit() {
            const url = this.id ? `admin/service/${this.id}` : `admin/service`
            await this.axios[this.id ? 'put' : 'post'](url, this.form)
            this.$router.push({name: 'admin.service.index'});
        }
    }
}
</script>

<style>

</style>
